from ..models.base_model import BaseModel
from .homework import Homework
from ..models.student import Student
from django.contrib.auth.models import User
from django.db import models

class HomeworkSubmission(BaseModel):
    """作业提交"""
    homework = models.ForeignKey(Homework, on_delete=models.CASCADE, related_name='submissions', verbose_name="作业")
    student = models.ForeignKey(Student, on_delete=models.CASCADE, related_name='homework_submissions', verbose_name="学生")
    submission_time = models.DateTimeField(null=True, blank=True, verbose_name="提交时间")
    STATUS_CHOICES = [
        ('excellent', '好'),
        ('good', '中'),
        ('poor', '差'),
        ('plagiarism', '抄袭'),
        ('missing', '未提交'),
    ]

    status = models.CharField(
        max_length=20, 
        choices=STATUS_CHOICES,
        default='good',
        verbose_name="完成情况"
    )
    feedback = models.TextField(blank=True, verbose_name="反馈")
    reviewed_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, related_name='reviewed_homeworks', verbose_name="批改人")
    reviewed_at = models.DateTimeField(null=True, blank=True, verbose_name="批改时间")

    def __str__(self):
        return f"{self.student} - {self.homework}"

    class Meta:
        verbose_name = "作业提交"
        verbose_name_plural = "作业提交"
        unique_together = ('homework', 'student')